{extend name="base/common"}

{block name="style"}
<link href="/static/summernote/summernote.css" rel="stylesheet">
<link href="/static/bootstrap-fileinput/css/fileinput.min.css" rel="stylesheet">
<link href="/static/js/jQuery-imgBox/imgbox.css" rel="stylesheet"/>
<style type="text/css">
    .note-editor.note-frame { border-radius: 0; border:0; margin-bottom: 0; }
    .front_cover_img {height: 40px; width: 40px; margin-top: 4px}
    .send_type_label {
        padding-left: 12px;
    }
</style>
{/block}

{block name="page-header"}

{/block}

{block name="main"}
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="mail-box-header">
            <div class="pull-right tooltip-demo">
                <!--<button url="{:Url('draft')}" class="btn btn-white btn-sm ajax-post" data-toggle="tooltip" data-placement="top"-->
                        <!--target-form="form-horizontal" data-edit="content">-->
                    <!--<i class="fa fa-pencil"></i> 保存草稿-->
                <!--</button>-->
                <a href="{:Url('index')}" class="btn btn-white btn-sm" data-toggle="tooltip" data-placement="top"><i class="fa fa-times"></i> 关闭</a>
            </div>
                <h2>
                    工会信息
                </h2>
        </div>
        <div class="mail-box">
            <form class="form-horizontal" method="post">
                <div class="mail-body">
                    <div class="form-group"><label class="col-sm-2 control-label">工会名称:</label>
                        <div class="col-sm-10"><input type="text" class="form-control" placeholder="工会名称" name="title" value='{$res.title}'></div>
                    </div>
                    <div class="form-group"><label class="col-sm-2 control-label">发布人:</label>
                        <div class="col-sm-10"><input type="text" class="form-control" placeholder="信息的发布者" name="source" value='{$res.source}'></div>
                    </div>


                    <div class="form-group"><label class="col-sm-2 control-label">封面图片:</label>
                        <div class="col-sm-10">
                            <input id="input-file" type="file" class="file">
                            <sapn>
                                {empty name="res.front_cover"}图片预览{else/}
                                <a class="front_cover" href="{$res.front_cover}">
                                    <img class="front_cover_img" src="{$res.front_cover}"/>
                                </a>
                                {/empty}
                            </sapn>
                        </div>
                    </div>
                    <div class="form-group"><label class="col-sm-2 control-label">工会类别:</label>
                        <div class="col-sm-10"><input type="text" class="form-control" placeholder="工会的类别" name="type" value='{$res.type}'></div>
                    </div>
                    <div class="form-group"><label class="col-sm-2 control-label">联系人:</label>
                        <div class="col-sm-10"><input type="text" class="form-control" placeholder="联系人" name="contact" value='{$res.contact}'></div>
                    </div>
                    <div class="form-group"><label class="col-sm-2 control-label">联系方式:</label>
                        <div class="col-sm-10"><input type="text" class="form-control" placeholder="联系方式" name="mobile" value='{$res.mobile}'></div>
                    </div>
                    <div class="form-group"><label class="col-sm-2 control-label">具体地址:</label>
                        <div class="col-sm-10"><input type="text" class="form-control" placeholder="具体地址" name="address" value='{$res.address}'></div>
                    </div>
                    <div class="form-group"><label class="col-sm-2 control-label">办公时间:</label>
                        <div class="col-sm-10"><input id="office_time_start" name="office_time_start"><span>{$res.office_time_start}</span>-至-<span>{$res.office_time_end}</span><input id="office_time_end" name="office_time_end"></div>
                    </div>


        </div>
                <div class="clearfix"></div>
                <div class="mail-body text-right tooltip-demo">

                    <button url="{:Url('add')}" class="btn btn-sm btn-primary ajax-post" target-form="form-horizontal"
                            data-toggle="tooltip" data-placement="top" data-edit="content">
                        <i class="fa fa-reply"></i> 添加
                    </button>
                    <!--<button url="{:Url('draft')}" class="btn btn-white btn-sm ajax-post" data-toggle="tooltip" data-placement="top"-->
                            <!--target-form="form-horizontal" data-edit="content">-->
                        <!--<i class="fa fa-pencil"></i> 保存草稿-->
                    <!--</button>-->
                    <a href="{:Url('index')}" class="btn btn-white btn-sm" data-toggle="tooltip" data-placement="top"><i class="fa fa-times"></i> 关闭</a>
                </div>
                <div class="clearfix"></div>
                <input type="hidden" name="id" value="{$res.id}">
                <input type="hidden" name="front_cover" value="{$res.front_cover}">
            </form>
        </div>
    </div>
</div>
{/block}

{block name="script"}
<script src="/static/summernote/summernote.min.js"></script>
<script src="/static/summernote/lang/summernote-zh-CN.js"></script>
<script src="/static/bootstrap-fileinput/js/fileinput.min.js"></script>
<script src="/static/bootstrap-fileinput/themes/fa/fa.js"></script>
<script src="/static/bootstrap-fileinput/js/locales/zh.js"></script>
<script src="/static/js/jQuery-imgBox/jquery.imgbox.js"></script>

<script type="text/javascript" src="/static/bootstrap-datetimepicker/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/static/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js" charset="UTF-8"></script>
<script type="text/javascript" src="/static/bootstrap-datetimepicker/js/bootstrap-datetimepicker.zh-CN.js"></script>
<link href="/static/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css" rel='stylesheet' type='text/css'>
<script>
    $(document).ready(function () {

        $('.summernote').summernote({
            lang: 'zh-CN',
            height: 300,
            minHeight: 210,
            callbacks: {
                onImageUpload: function (files) { //the onImageUpload API
                    img = sendFile(files[0]);
                }
            }
        });

        function sendFile(file) {
            var data = new FormData();
            data.append("file_data", file);
            $.ajax({
                data: data,
                type: "POST",
                url: "{:Url('Upload/picture')}",
                cache: false,
                contentType: false,
                processData: false,
                success: function(response) {
                    var data = $.parseJSON(response);
                    $(".summernote").summernote('insertImage', data.data, 'image name'); // the insertImage API
                }
            });
        }

        console.log($(this).val())
        $('.send_type').on('ifChecked', function(event){
            switch ($(this).val()) {
                case '0' :
                    $("#send_target").empty();
                    $("#send_target").append("<option value='0'>所有人</option>");
                    break;
                case '1':
                    $.ajax({
                        type: "get",
                        url: "{:Url('getDepartment')}",
                        success: function(response) {
                            $("#send_target").empty();
                            $.each(response.department, function(i,item){
                                $("#send_target").append("<option value='"+item.id+"'>"+item.name+"</option>");
                            });
                        }
                    });
                    break;
                case '2':
                    $.ajax({
                        type: "get",
                        url: "{:Url('getTag')}",
                        success: function(response) {
                            $("#send_target").empty();
                            $.each(response.taglist, function(i,item){
                                $("#send_target").append("<option value='"+item.tagid+"'>"+item.tagname+"</option>");
                            });
                        }
                    });
                    break;
            }
        });
    });

    $("#input-file").fileinput({
        showPreview: false,
        language: 'zh', //设置语言
        uploadUrl: '{:Url("Upload/picture")}', //上传的地址
        allowedFileExtensions: ['png','jpg','gif','png','jpeg'],
        maxFileSize: 1024 * 200,
    }).on("filebatchselected", function(event, files) {
        $(this).fileinput("upload");
    }).on('fileuploaded', function(event, data, previewId, index) {
        var response = $.parseJSON(data.response);
        if(response.code == 1) {
            $("input[name='front_cover']").val(response.data);
        } else {
            updateAlert(response.msg, 'warning');
        }
    });

    $(".front_cover").imgbox({
        overlayShow: false,
        hideOnContentClick: true,
        slideshow: false,
        theme: 'dark',
        alignment: 'center',       // Position - may be auto OR center.
        allowMultiple: false,
    });


//选择时间插件
    $('#office_time_start,#office_time_end').datetimepicker({
        format: 'hh:ii',//日期的格式
        startDate:'1900-01-01',//选择器的开始日期
        autoclose:true,//日期选择完成后是否关闭选择框
        bootcssVer:3,//显示向左向右的箭头
        language:'zh_CN',//语言
        startView: "hour",
        minView: "hour",//表示日期选择的最小范围，默认是hour


    });




        highlight_subnav("{:Url('UnionLoabour/index')}");




</script>
{/block}